<html>
<head>
	<title>SQL Relay Command Line Programs</title>
	<link rel="stylesheet" href="../css/styles.css">
</head>
<body>
<h1>SQL Relay Command Line Programs</h1>

<ul>
  <li><a href="#sqlrstart">Starting SQL Relay</a></li>
  <li><a href="#stopping"">Stopping SQL Relay</a></li>
  <li><a href="#cmdline">Command Line Clients</a></li>
  <li><a href="#status">The Status Monitor</a></li>
</ul>

<a name="sqlrstart"/><h2>Starting SQL Relay</h2>

<p>Before attempting to start SQL Relay, you must create a configuration file, see <a href="configurationguide.html">SQL Relay Configuration Guide</a> for detailed instructions.</p>

<p>Assuming you have created a configuration file...</p>

<p>Use the <b>sqlr-start</b> program to start the SQL Relay server processes.</p>

<blockquote>
  <pre>sqlr-start [-id ID] [-config CONFIGFILE] [-localstatedir LOCALSTATEDIR]
</pre>

</blockquote>
<p>When run with the -id option, <b>sqlr-start</b> starts one instance of <b>sqlr-listener</b>, one instance of <b>sqlr-scaler</b> and the number of <b>sqlr-connection</b> daemons specified in the config file for the given ID.</p>

<p>When run without the -id option, <b>sqlr-start</b> starts <b>sqlr-listener</b>, <b>sqlr-scaler</b> and <b>sqlr-connection</b> daemons as appropriate for each instance in the config file(s) whose enabled parameter is set to "yes".</p>

<p>The optional -config CONFIGFILE argument may be used to specify a config file, directory containing a set of config files, a url that resolves to a config file, or a comma-separated list of any of the above.  See the sections on <a href="configguide.html#specifying">Specifying Configuration Files</a> and <a href="configguide.html#remote">Remote Configuration Files</a> in the SQL Relay Configuration Guide for more info.</p>

<p>If the optional -localstatedir LOCALSTATEDIR argument is used, it is passed to the programs started by <b>sqlr-start</b> as appropriate.</p>

<a name="stopping"/><h2>Stopping SQL Relay</h2>

<p>The <b>sqlr-stop</b> command is provided to kill running instances of SQL Relay.  It accepts an optional argument: the id of the instance to kill.</p>

<blockquote>
  <pre>sqlr-stop [-id ID]
</pre>

</blockquote>
<p>Running it with an ID kills SQL Relay processes that were started with the supplied ID.  Running it with no arguments will kill all SQL Relay processes.</p>

<a name="cmdline"/><h2>Command Line Clients</h2>

<p>Several command line utilities are provided for use with SQL Relay.  The syntax for each is as follows:</p>

<blockquote>
  <pre>sqlrsh -host HOST -port PORT -socket SOCKET -user USER -password PASSWORD [-script SCRIPT | -command COMMAND] [-quiet] [-format plain|csv] [-resultsetbuffersize rows]
sqlr-export -host HOST -port PORT -socket SOCKET -user USER -password PASSWORD (-table TABLE | -sequence SEQUENCE) &gt; exportfile.xml
sqlr-import -host HOST -port PORT -socket SOCKET -user USER -password PASSWORD -file exportfile.xml
</pre>

</blockquote>
<p>or, if there's a configuration file that the client can read:</p>

<blockquote>
  <pre>sqlrsh -id ID [-config CONFIGFILE] [-script SCRIPT | -command COMMAND] [-quiet] [-format plain|csv] [-resultsetbuffersize rows]
sqlr-export -id ID [-config CONFIGFILE] (-table TABLE | -sequence SEQUENCE) &gt; exportfile.xml
sqlr-import -id ID [-config CONFIGFILE] -file exportfile.xml
</pre>

</blockquote>
<p>The -host, -port, -socket, -user, and -password arguments specify which listener to connect to and what authentication to use.</p>

<p>The -id argument refers to an entry in a configuration file from which host, port, socket, user and passwords can be read.</p>

<p>The -config argument works the same way as described above for sqlr-start.</p>

<p><b>sqlrsh</b> is an interactive query tool similar to sqlplus, mysql, psql, isql and the like.  Run it and type help; at the prompt for detailed usage instructions.  When sqlrsh starts up, it reads and executes two rc files, the system rc file (most likely /usr/local/firstworks/etc/sqlrshrc) and a personal rc file .sqlrshrc in your home directory.  These files should contain sqlrsh commands, ending in semicolons, seperated by carraige returns.  Any sqlrsh commands may be used in the rc files, even queries.  If a SCRIPT is supplied with the -script option, then the script is run and sqlrsh exits.  The script can contain any sqlrsh commands, incluing queries.  If a COMMAND is supplied with the -command option, then the command is run and sqlrsh exits.  The command can be single sqlrsh command (or query) or a list of semicolon-delimited commands (or queries).</p>

<p>The <b>sqlr-export</b> command exports the specified table or sequence to a file from which <b>sqlr-import</b> can later re-import it.</p>

<p>The <b>sqlr-import</b> command reads the specified file and imports the data contained in the file into the table or sequence specified in the file.  Note, that <b>sqlr-import</b> does not create tables or sequences, it just imports data into an already-existing table or sequence.</p>

<p><b>sqlr-export</b> and <b>sqlr-import</b> may be used to export data from one database and import it into another database, even if the databases are dissimilar (eg. one is <a href="PostgreSQL">PostgreSQL</a> and the other is <a href="MySQL">MySQL</a>), if the structures of the tables in both databases are compatible.</p>

<p>On Windows the command-line clients can be run from the Windows Command Line.  Adding C:\Program Files\Firstworks\bin to the PATH environment variable makes this easier, though is is not essential.  You could just change directories to C:\Program Files\Firstworks\bin and run the programs from there.</p>

<a name="status"/><h2>The Status Monitor</h2>

<p>The <b>sqlr-status</b> program displays statistics about a running SQL Relay instance.  You can run it as follows, replacing <i>instance</i> with the name of the SQL Relay instance that you would like to read statistics from: </p>

<blockquote>
<tt>sqlr-status -id</tt> <i>instance</i>
</blockquote>
<p>Currently it generates output like:</p>

<blockquote>
  <pre>  Instance State             :  Enabled

  Open   Database Connections:  2
  Opened Database Connections:  2

  Open   Database Cursors:      2
  Opened Database Cursors:      4

  Open   Client Connections:    0
  Opened Client Connections:    0

  Times  New Cursor Used:       0
  Times  Cursor Reused:         0

  Total  Queries:               0
  Total  Errors:                0

  Forked Listeners:             0

Scaler's view:
  Connections:                  2
  Connected Clients:            0

Mutexes:
  Connection Announce               : not acquired (0)
  Shared Memory Access              : acquired     (1)
  Connection Count                  : acquired     (1)
  Session Count                     : acquired     (1)
  Open Connections/Forked Listeners : acquired     (1)

Triggers:
  Accept Available Connection (l-w, c-s)         : triggered     (1)
  Done Accepting Available Connection (c-w, l-s) : not triggered (0)
  Evaluate Connection Count (s-w, l-s)           : not triggered (0)
  Done Evaluating Connection Count (l-w, s-s)    : not triggered (0)
  Connection Has Started (s-w, c-s)              : not triggered (0)

Counts:
  Busy Listener Count : 0

Raw Semaphores:
  +-------------------------------------------------------+
  | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |  10 | 11 | 12 |
  +---+---+---+---+---+---+---+---+---+---+-----+----+----+
  | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 1 |   0 |  0 |  0 |
  +-------------------------------------------------------+
</pre>

</blockquote>
<p>Here are descriptions of the statistics:</p>

<ul>
  <li>Open Database Connections: The number of database connections that are currently open.</li>
  <li>Opened Database Connections: The total number of database connections that have been opened since the instance was started.</li>
  <li>Open Database Cursors: The number of database cursors that are currently open.</li>
  <li>Opened Database Cursors: The total number of database cursors that have been opened since the instance was started.</li>
  <li>Open Client Connections: The number of SQL Relay clients that are currently connected to the SQL Relay server.</li>
  <li>Opened Server Connections: The total number of SQL Relay clients that have connected to this instance of the SQL Relay server since the instance was started.</li>
  <li>Times New Cursor Used: The number of times a cursor couldn't be reused.</li>
  <li>Times Cursor Reused: The number of times a cursor could be reused.</li>
  <li>Total Queries: The total number of queries that have been run through this instance.</li>
  <li>Total Errors: The total number of queries that generated errors.</li>
  <li>Forked Listeners: The total number of child listener processes that are running.  This roughly corresponds to the number of clients that are waiting to access the database.</li>
</ul>

<p>The rest of the stats are useful when reporting suspected bugs but are much more value to SQL Relay developers than users.
</p>

</body>
</html>
